package br.uesc.newigrafu.swing.controle;

import br.uesc.newigrafu.dominio.NewIGrafu;
import br.uesc.newigrafu.swing.visao.PainelReconstrucao;
import br.uesc.newigrafu.swing.visao.JanelaDigrafu;
import br.uesc.newigrafu.swing.visao.PainelDigrafu;

import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.JFileChooser;
import javax.swing.JDialog;

import java.io.File;

public class ControlePainelReconstrucao implements
    ActionListener, ListSelectionListener {

    NewIGrafu newIGrafu = null;
    PainelReconstrucao painelReconstrucao = null;
    JanelaDigrafu jDigrafu = null;

    public ControlePainelReconstrucao(NewIGrafu _newIGrafu,
            PainelReconstrucao _painelReconstrucao) {
        newIGrafu = _newIGrafu;
        painelReconstrucao = _painelReconstrucao;
    }

    public void actionPerformed(ActionEvent e) {
        Component fonte = (Component) e.getSource();
        String comando = e.getActionCommand();

        if (comando.equals("CarregarArquivoSequencia")) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int rtn = fileChooser.showOpenDialog(fonte);
            if (rtn == JFileChooser.APPROVE_OPTION) {
                // Domínio?? (ArquivoSequencia)
                File arqseq = fileChooser.getSelectedFile();
                // entrada = arqseq.getName();
                System.out.println("Arquivo carregado: " + arqseq.getName());
                painelReconstrucao.getCampoTextoArquivoEntrada().setText(
                    arqseq.getPath());
                // newIGrafu.atribuiSequencia(painelReconstrucao.getID(),
                //     arqseq.getPath());
            }
        }    
        else if (comando.equals("AlterarParametrosPrograma")) {
            jDigrafu = new JanelaDigrafu(new PainelDigrafu(newIGrafu));
            // JDialog dialogoParametros = new JDialog(painelReconstrucao);
            // dialogoParametros.setContentPane(new PainelDigrafu(newIGrafu));
        }
    }

    public void valueChanged(ListSelectionEvent lse) {
        if (lse.equals("ml")) {
        } else if (lse.equals("distancia")) {
        }
    }
}
